Skip to content

[Enhancement] Import by natural key fields#11288

Merged
SchrodingersGat merged 20 commits intoinventree:masterfrom
SchrodingersGat:import-pk-field
Feb 20, 2026
Merged

[Enhancement] Import by natural key fields#11288
SchrodingersGat merged 20 commits intoinventree:masterfrom
SchrodingersGat:import-pk-field

Conversation

@SchrodingersGat
Copy link
Member

@SchrodingersGat SchrodingersGat commented Feb 11, 2026

This PR allows for data importing by "natural key" fields on related models. Instead of forcing data import by primary key (pk) value only, other fields can be used for lookup.

Examples

  • Lookup 'Part' by IPN
  • Lookup 'SupplierPart' by SKU
  • Lookup 'SalesOrder' by reference

Related Issues

TODO

  • Support wider range of models with natural keys
  • Updated playwright tests
  • Enhanced documentation around data import

@SchrodingersGat SchrodingersGat added this to the 1.3.0 milestone Feb 11, 2026
@SchrodingersGat SchrodingersGat added enhancement This is an suggested enhancement or new feature import / export Data importing, exporting and processing feature full-run Always do a full QC CI run labels Feb 11, 2026
@netlify
Copy link

netlify bot commented Feb 11, 2026

Deploy Preview for inventree-web-pui-preview canceled.

Name Link
🔨 Latest commit 47c0295
🔍 Latest deploy log https://app.netlify.com/projects/inventree-web-pui-preview/deploys/6997cf1528e51b0008068758

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces natural key field support for data imports in InvenTree, allowing related models to be referenced by human-readable identifiers (like IPN, SKU, MPN) instead of requiring primary key values. This enhancement makes importing data from external sources more intuitive and reduces the need for manual ID lookups.

Changes:

  • Added lookup_related_field method to perform natural key lookups on related fields during import
  • Added get_related_model method to retrieve related model classes for field lookups
  • Defined IMPORT_ID_FIELDS on multiple models (Part, PartCategory, PartTestTemplate, Company, ManufacturerPart, SupplierPart, Order, Build) to specify which fields can be used for natural key lookups

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 10 comments.

Show a summary per file
File Description
src/backend/InvenTree/importer/models.py Core implementation of natural key lookup functionality with lookup_related_field and get_related_model methods
src/backend/InvenTree/part/models.py Added IMPORT_ID_FIELDS for Part, PartCategory, and PartTestTemplate models
src/backend/InvenTree/company/models.py Added IMPORT_ID_FIELDS for Company, ManufacturerPart, and SupplierPart models
src/backend/InvenTree/order/models.py Added IMPORT_ID_FIELDS to abstract Order model
src/backend/InvenTree/build/models.py Added IMPORT_ID_FIELDS to Build model

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@codecov
Copy link

codecov bot commented Feb 11, 2026

Codecov Report

❌ Patch coverage is 34.84848% with 43 lines in your changes missing coverage. Please review.
✅ Project coverage is 87.98%. Comparing base (1ac3f5e) to head (47c0295).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #11288      +/-   ##
==========================================
- Coverage   88.04%   87.98%   -0.07%     
==========================================
  Files        1292     1292              
  Lines       58655    58720      +65     
  Branches     1943     1943              
==========================================
+ Hits        51645    51667      +22     
- Misses       6526     6569      +43     
  Partials      484      484              
Flag Coverage Δ
backend 89.18% <34.84%> (-0.08%) ⬇️
migrations 42.16% <27.27%> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
Backend Apps 91.70% <32.81%> (-0.11%) ⬇️
Backend General 93.37% <100.00%> (+<0.01%) ⬆️
Frontend 70.88% <ø> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@codspeed-hq
Copy link

codspeed-hq bot commented Feb 19, 2026

Merging this PR will degrade performance by 9.26%

⚠️ Unknown Walltime execution environment detected

Using the Walltime instrument on standard Hosted Runners will lead to inconsistent data.

For the most accurate results, we recommend using CodSpeed Macro Runners: bare-metal machines fine-tuned for performance measurement consistency.

❌ 1 regressed benchmark
✅ 43 untouched benchmarks

⚠️ Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Mode Benchmark BASE HEAD Efficiency
WallTime test_api_list_performance[/api/build/item/] 298.1 ms 328.5 ms -9.26%

Comparing SchrodingersGat:import-pk-field (47c0295) with master (1ac3f5e)

Open in CodSpeed

@SchrodingersGat SchrodingersGat merged commit 14d6d23 into inventree:master Feb 20, 2026
38 of 39 checks passed
@SchrodingersGat SchrodingersGat deleted the import-pk-field branch February 20, 2026 04:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement This is an suggested enhancement or new feature feature full-run Always do a full QC CI run import / export Data importing, exporting and processing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FR] Add IPN as matching field for BoM import [Importer] Natural Key Support

2 participants